package cn.edu.gench.learn.day9;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by zhuzhongbiao on 2017/4/26.
 */
@Controller
@RequestMapping(value = "/test")
public class TestController {

    @Autowired
    private CityService cityService;

    @ResponseBody
    @RequestMapping(value = "/hi")
    public String hi(HttpServletRequest request){
        String name  = request.getParameter("name");

        return "hello world" + name;
    }

    @ResponseBody
    @RequestMapping(value = "/city")
    public List<CityModel> getCity(HttpServletRequest request){
        return  cityService.showCity();
    }



    //"100" = 100
    @ResponseBody
    @RequestMapping(value = "/city/one")
    public CityModel getCityOne(HttpServletRequest request){
        int id  = Integer.parseInt(request.getParameter("id"));//字符串装换成数字
        return  cityService.showCityOne(id);
    }

}
